package study.saas.order.service;

import org.springframework.stereotype.Service;
import study.saas.order.entity.Commodity;
import study.saas.order.service.model.CommodityLotteryDTO;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class LotteryService {
    @Resource
    private LotteryFacade lotteryFacade;
    @Resource
    private CommodityFacade commodityFacade;

    /**
     * 获取参与抽奖的产品
     * @return
     */
    public List<CommodityLotteryDTO> getCommodity() {
        String[] commodityNames = {"小米手机","苹果手机","ipadPro","外星人电脑","华为显示器","零食","台灯","小米音响","5元优惠卷"};
        ArrayList<CommodityLotteryDTO> commodityList = new ArrayList<>();
        for (int i = 0; i < commodityNames.length; i++) {
            Commodity data = commodityFacade.findCommodity(commodityNames[i]).getData();

            CommodityLotteryDTO commodityLotteryDTO = new CommodityLotteryDTO();
            commodityLotteryDTO.setNumber(i);
            commodityLotteryDTO.setCommodityName(data.getCommodityName());

            commodityList.add(commodityLotteryDTO);
        }
        return commodityList;
    }
}
